package com.bafenyi.zh.bafenyilib.base;


import android.os.Bundle;
import android.util.Log;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;

import com.bafenyi.zh.bafenyilib.R;
import com.gyf.immersionbar.ImmersionBar;
import butterknife.ButterKnife;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public abstract class BFYBaseActivity extends SwipeBackActivity {
    private boolean is_first;

    /**
     * 是否成功获取配置参数
     **/
    public interface PermissionsLinsten {
        void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults);
    }


    protected ImmersionBar mImmersionBar;

    public PermissionsLinsten permissionsLinsten;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        is_first = true;
        onPrepareCreate();
        super.onCreate(savedInstanceState);
        setContentView(getBaseLayout());

        initImmersionBar();

        ButterKnife.bind(this);

        getSwipeBackLayout();

        initBaseView(savedInstanceState);

    }



    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        if (!is_first) return;
        is_first = false;
        initAnylayerShow();
    }

    /**准备生成窗口**/
    protected abstract void onPrepareCreate();

    /**关联layout**/
    @LayoutRes
    protected abstract int getBaseLayout();

    protected abstract void initBaseView(Bundle saveInstanceState);

    protected abstract void initAnylayerShow();

    private void initImmersionBar() {
        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.keyboardEnable(true);
        mImmersionBar.navigationBarColor(R.color.color_ffffff_100);
        mImmersionBar.statusBarDarkFont(true);

        mImmersionBar.init();
    }
    public void setBarForWhite(){
        mImmersionBar.statusBarDarkFont(false);
        mImmersionBar.init();
    }
    public void setBarForBlack(){
        mImmersionBar.statusBarDarkFont(true);
        mImmersionBar.init();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (permissionsLinsten != null) {
            permissionsLinsten.onRequestPermissionsResult(requestCode , permissions , grantResults);
        }
    }
}

